package com.ch.spring_boot_mystarters;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(MyProperties.class)
@ConditionalOnClass(MyService.class)
@ConditionalOnProperty(prefix="my",value="enabled",matchIfMissing = true)
public class MyAutoConfiguration {
      @Autowired
      private MyProperties myProperties;
      @Bean
      @ConditionalOnMissingBean(MyService.class)
      public MyService myService() {
		// TODO Auto-generated method stub
    	MyService myService = new MyService();
    	myService.setMsg(myProperties.getMsg());  
		return myService;
	}
}
